﻿// CShapeDlg.cpp: 实现文件

#include "pch.h"
#include "XiaoDuDrawing.h"
#include "afxdialogex.h"
#include "CShapeDlg.h"


// CShapeDlg 对话框
IMPLEMENT_DYNAMIC(CShapeDlg, CDialogEx)

//构造函数
CShapeDlg::CShapeDlg(CShape* cur_pShape, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SHAPE_DLG, pParent),//使用初始化列表
	cur_pShape(cur_pShape),
	m_strType("Square"),
	m_Type(SQUARE),
	m_x(0), m_y(0),
	m_w(0), m_h(0), m_text(_T("")),
	m_pen_width(0), m_pen_type(0), m_brush_type(0),
	m_pen_color(0), m_brush_color(0)
{
	
}

//CShapeDlg::CShapeDlg(CWnd* pParent/* = nullptr*/)
//	: CDialogEx(IDD_SHAPE_DLG, pParent)
//	, m_x(0)
//	, m_y(0)
//	, m_w(0)
//	, m_h(0)
//	, m_pen_type(0)
//	, m_pen_width(0)
//	, m_brush_type(0)
//	, m_text(_T(""))
//	, m_strType(_T(""))
//	
//	//初始化列表初始化
//{
//
//}


CShapeDlg::~CShapeDlg()
{
}


void CShapeDlg::DoDataExchange(CDataExchange* pDX)
{
	//控件与成员变量关联
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_X, m_x);
	DDX_Text(pDX, IDC_EDIT_Y, m_y);
	DDX_Text(pDX, IDC_EDIT_W, m_w);
	DDX_Text(pDX, IDC_EDIT_H, m_h);
	DDX_Text(pDX, IDC_BUTTON_COLOR1, m_pen_color);
	DDX_LBIndex(pDX, IDC_LIST_PENT, m_pen_type);
	DDX_Text(pDX, IDC_EDIT_LINEW, m_pen_width);
	DDX_Text(pDX, IDC_BUTTON_COLOR2, m_brush_color);
	DDX_Text(pDX, IDC_EDIT_T, m_text);
	DDX_Control(pDX, IDC_LIST_PENT, m_lstName1);
	DDX_Control(pDX, IDC_LIST_BRUSHT, m_lstName2);
	DDX_LBIndex(pDX, IDC_LIST_BRUSHT, m_brush_type);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_cmbType);
	DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
	DDX_Control(pDX, IDC_BUTTON_COLOR1, m_penColorBtn);
	DDX_Control(pDX, IDC_BUTTON_COLOR2, m_brushColorBtn);
}


//BEGIN_MESSAGE_MAP(CShapeDlg, CDialogEx)
//	ON_BN_CLICKED(IDOK, &CShapeDlg::OnBnClickedOk)
//END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CShapeDlg, CDialog)
	ON_WM_ACTIVATE()
	ON_LBN_SELCHANGE(IDC_LIST_PENT, &CShapeDlg::OnLbnSelchangeListPenT)
	ON_LBN_SELCHANGE(IDC_LIST_BRUSHT, &CShapeDlg::OnLbnSelchangeListBrushT)
	ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CShapeDlg::OnCbnSelchangeCombo1)
	ON_BN_CLICKED(IDOK, &CShapeDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CShapeDlg::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_BUTTON_COLOR1, &CShapeDlg::OnBnClickedButtonColor1)
	ON_BN_CLICKED(IDC_BUTTON_COLOR2, &CShapeDlg::OnBnClickedButtonColor2)
END_MESSAGE_MAP()


// CShapeDlg 消息处理程序

BOOL CShapeDlg::OnInitDialog()
{

	CDialog::OnInitDialog();
	//线型
	m_lstName1.AddString(TEXT("PS_SOLID"));
	m_lstName1.AddString(TEXT("PS_DASH"));
	m_lstName1.AddString(TEXT("PS_DOT"));
	m_lstName1.AddString(TEXT("PS_DASHDOT"));
	m_lstName1.AddString(TEXT("PS_DASHDOTDOT"));
	m_lstName1.AddString(TEXT("PS_NULL"));
	m_lstName1.AddString(TEXT("PS_INSIDEFRAME"));
	//画刷风格
	m_lstName2.AddString(TEXT("HS_HORIZONTAL"));
	m_lstName2.AddString(TEXT("HS_VERTICAL"));
	m_lstName2.AddString(TEXT("HS_FDIAGONAL"));
	m_lstName2.AddString(TEXT("HS_BDIAGONAL"));
	m_lstName2.AddString(TEXT("HS_CROSS"));
	m_lstName2.AddString(TEXT("HS_DIAGCROSS"));
	
	m_penColorBtn.EnableAutomaticButton(_T("默认"), RGB(0, 0, 0));
	m_penColorBtn.EnableOtherButton(_T("其余颜色"));
	m_penColorBtn.SetColor((COLORREF)-1);
	m_penColorBtn.SetColumnsNumber(10);

	m_brushColorBtn.EnableAutomaticButton(_T("默认"), RGB(0, 0, 0));
	m_brushColorBtn.EnableOtherButton(_T("其余颜色"));
	m_brushColorBtn.SetColor((COLORREF)-1);
	m_brushColorBtn.SetColumnsNumber(10);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}



void CShapeDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);

	// TODO: 在此处添加消息处理程序代码
	// WA_ACTIVE:被鼠标点击以外的方法激活,WA_CLICKACTIVE:由鼠标点击激活,WA_INACTIVE:失去激活。
	if (nState == WA_ACTIVE) //窗口被激活
		UpdateData(FALSE);
	else
		UpdateData(TRUE);
}



void CShapeDlg::OnLbnSelchangeListPenT()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
	switch (m_lstName1.GetCurSel())
	{
	case 0:m_pen_type = PS_SOLID;
	case 1:m_pen_type = PS_DASH;
	case 2:m_pen_type = PS_DOT;
	case 3:m_pen_type = PS_DASHDOT;
	case 4:m_pen_type = PS_DASHDOTDOT;
	case 5:m_pen_type = PS_NULL;
	case 6:m_pen_type = PS_INSIDEFRAME;
	}
}


void CShapeDlg::OnLbnSelchangeListBrushT()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData();
	switch (m_lstName2.GetCurSel())
	{
	case 0:m_brush_type = HS_HORIZONTAL;
	case 1:m_brush_type = HS_VERTICAL;
	case 2:m_brush_type = HS_FDIAGONAL;
	case 3:m_brush_type = HS_BDIAGONAL;
	case 4:m_brush_type = HS_CROSS;
	case 5:m_brush_type = HS_DIAGCROSS;
	}
}

void CShapeDlg::OnCbnSelchangeCombo1()
{
	// TODO: 在此添加控件通知处理程序代码
	int nIndex = m_cmbType.GetCurSel();//获取当前选中的项的索引
	m_cmbType.GetLBText(nIndex, m_strType);
	if (m_strType == "Square")
	{
		m_Type = SQUARE;
	}
	if (m_strType == "Rectangle")
	{
		m_Type = RECTANGLE;
	}
	if (m_strType == "Circle")
	{
		m_Type = CIRCLE;
	}
	if (m_strType == "Ellipse")
	{
		m_Type = ELLIPSE;
	}
	if (m_strType == "Triangle")
	{
		m_Type = TRIANGLE;
	}
	if (m_strType == "Text")
	{
		m_Type = TEXT;
	}
}



void CShapeDlg::OnBnClickedButtonColor1()
{
	// TODO: 在此添加控件通知处理程序代码
	COLORREF color = m_penColorBtn.GetColor();
	if (color == -1)
	{
		color = m_penColorBtn.GetAutomaticColor();
	}
}


void CShapeDlg::OnBnClickedButtonColor2()
{
	// TODO: 在此添加控件通知处理程序代码
	COLORREF color = m_brushColorBtn.GetColor();
	if (color == -1)
	{
		color = m_brushColorBtn.GetAutomaticColor();
	}
}

void CShapeDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	 // 使用DDX机制将控件中的数据传输到成员变量
	UpdateData(TRUE);
	CDialogEx::OnOK();
}

void CShapeDlg::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialog::OnCancel();
}